Chapter 6 Synchronization Tools

Chapter 6 Synchronization Tools

Background

  • 背景

    alt text
    alt text
    alt text
    alt text

  • 生產者

    alt text

  • 消費者

    alt text

  • 競爭條件

    • count++

      alt text

    • fork()

      alt text

The Critical-Section Problem

  • 關鍵區域

    alt text
    alt text
    alt text

    • Example

      alt text

  • Solution

    alt text
    alt text

Peterson’s Solution

  • sol

    alt text
    alt text
    alt text
    alt text

  • example

    alt text
    alt text

  • 現代框架可能不適用

    alt text
    alt text

    • 雙方都進入CS

      alt text
      alt text
      alt text

Hardware Support for Synchronization

  • 不同processor

    alt text
    alt text
    alt text

  • 三種硬體支援

    alt text

  • 記憶體屏障

    alt text
    alt text

    • Example

      alt text
      alt text

    • method

      alt text

  • 關鍵區域以及鎖

    alt text

  • 同步硬體

    alt text
    alt text

  • test and set

    alt text
    alt text

    • 用法

      alt text

  • compare and swap

    alt text
    alt text

    • 用法

      alt text

  • Swap

    alt text
    alt text

    • 用法

      alt text

  • 上述三者仍舊不圓滿

    alt text

  • 原子變數

    alt text

    • increment

      alt text
      alt text

Mutex Locks

  • 互斥鎖

    alt text

    • 說明

      alt text
      alt text
      alt text
      alt text
      alt text

  • 定義

    alt text

Semaphores

  • 信號量

    alt text
    alt text
    alt text
    alt text
    alt text

  • 更加廣泛

    alt text
    alt text
    alt text

  • 實作

    alt text
    alt text
    alt text
    alt text

    • 說明

      alt text
      alt text
      alt text
      alt text
      alt text

  • 問題

    alt text

Monitors

  • 監視器

    alt text
    alt text
    alt text
    alt text
    alt text
    alt text

條件

  • 條件

    alt text
    alt text
    alt text

    • 順序

      alt text
      alt text
      alt text

    • A

      alt text
      alt text

    • B

      alt text
      alt text

    • 結論

      alt text
      alt text

Example

  • Example

    alt text
    alt text

實現monitor

  • 實現monitor

    alt text
    alt text
    alt text
    alt text
    alt text
    alt text
    alt text
    alt text
    alt text

錯誤使用monitor

  • 錯誤使用monitor

    alt text
    alt text
    alt text
    alt text
    alt text
    alt text
    alt text

Liveness

alt text
alt text
alt text
alt text
alt text
alt text

死鎖

alt text

飢餓 與 優先級導置

alt text
alt text
alt text
alt text
alt text

  • Some level of priority inversion can not be avoided!!

Chapter 6 Synchronization Tools
https://z-hwa.github.io/webHome/[object Object]/Operation Systems/Chapter-6-Synchronization-Tools/
作者
crown tako
發布於
2025年1月8日
許可協議